  function [e,into]=ch_field(into,fname,vs); 
% function [e,into]=ch_field(into,fname,vs); 
%
% CHeck if the structure into has a field with name fname
%
% In case it does not or if empty 
% then set it to vs 
% where vs can be numeric or string 
%
% If vs is not defined then into is not modified 
%
% Output e == 1 if field existed 
%        e == 0 if had to be created 
%
% alejandro justiniano 6/18/04 

if isstr( fname )==0 
error('2nd Input FNAME must be a string'); 
end 


e=isfield(into,fname); 
if e==1 
    d=getfield(into,fname); 
    g=isempty(d) ;
end 
if e==0 | g == 1 
    if nargin == 3 
        into=setfield(into,fname,vs);
    end
end 